package com.market.cash.ui.presenter

import android.graphics.Color
import com.market.cash.CashRootApps
import com.market.cash.R
import com.market.cash.http.ApiService
import com.market.cash.http.ApiService.addCommonParams
import com.market.cash.http.IHttpCallback
import com.market.cash.pro.ProPresenter
import com.market.cash.ui.view.ICashRootUserView
import com.market.cash.utils.helper.CashRootCommentDialogHelper
import com.market.cash.weight.banner.entity.CashRootBannerInfo
import org.json.JSONObject

/**
 * CashRoot
 * @Author wwdeng
 * @CreateTime: 2024/10/28 13:45
 * @Annotation：个人中心 Presenter 实现
 */
class CashRootUserPresenter(private val iView: ICashRootUserView) : ProPresenter(iView) {

    /**
     * 获取banner
     */
    fun loadCashRootBannerDataAction(){
        val bannerList = arrayListOf<CashRootBannerInfo>()
        val banner1 = CashRootBannerInfo()
        banner1.bannerResId = R.mipmap.cash_banner1
        banner1.bannerText = CashRootApps.app.getString(R.string.banner_text1)
        banner1.bannerTextColor = Color.parseColor("#A04A1B")
        bannerList.add(banner1)

        val banner2 = CashRootBannerInfo()
        banner2.bannerResId = R.mipmap.cash_banner2
        banner2.bannerText = CashRootApps.app.getString(R.string.banner_text2)
        banner2.bannerTextColor = Color.parseColor("#9D481E")
        bannerList.add(banner2)

        val banner3 = CashRootBannerInfo()
        banner3.bannerResId = R.mipmap.cash_banner3
        banner3.bannerText = String.format(CashRootApps.app.getString(R.string.banner_text3),CashRootApps.app.getString(R.string.app_name))
        banner3.bannerTextColor = Color.parseColor("#3033CF")
        bannerList.add(banner3)

        iView.showCashRootBannerList(bannerList)
    }

    /**
     * 获取评分配置
     */
    fun loadCashRootScoreCommentAction() {
        iView.showCashRootLoading()
        val httpUrl = ApiService.getHttpUrl(ApiService.API_URL.CASHROOT_API_COMMON_URL)
        val params = JSONObject().addCommonParams().apply {
            put("path", ApiService.API_PATH.CASHROOT_API_STAR_COMMENT_PATH)
        }
        doCashRootPostAction(httpUrl,params,object : IHttpCallback {
            override fun onRequestSuccess(data: JSONObject) {
                val obj = data.optJSONObject("obj")
                if (obj != null) {
                    CashRootCommentDialogHelper.showStarDialog(iView.getAct(),obj,false)
                }
            }

            override fun onRequestError(error: JSONObject) {
            }

            override fun onRequestFinish() {
                iView.hideCashRootLoading()
            }
        })
    }
}